import { HttpSrv, Utils } from 'lfun-bg-comp';
import { PageParams, PageResult, Result } from '..';

export interface SearchOrgParams {
  parent_id?: any;
  school_id?: any;
}

export interface Org {
  /**
   * ID 编号
   */
  id?: any;
  /**
   * 成员人数
   */
  member_cnt?: number;
  /**
   * 组织名称
   */
  org_name: string;
  /**
   * 上层组织id,第一层默认0
   */
  parent_id: any;
  /**
   * 所属学校id
   */
  school_id: any;
}

// 分页查询
export const searchOrg = (params: SearchOrgParams & PageParams): Result<PageResult<Org>> =>
  HttpSrv().get('/school/v1/organization/page', {
    params: { page: 1, per_page: 3000, school_id: Utils.getProps('schoolInfo')?.school_id, ...params },
  });
// 创建组织
export const createOrg = (params: Org): Result<Org> => HttpSrv().post('/school/v1/organization/', params);

export const updateOrg = (params: Org): Result<Org> => HttpSrv().put('/school/v1/organization/', params);
// 删除
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
export const deleteOrg = (org_id: any): Result<Org> =>
  HttpSrv().delete(`/school/v1/organization/`, { params: { org_id } });

export interface SearchMembersParams {
  /**
   * 这里给一个集合保证父能查询到子的所有成员
   */
  org_ids?: string;
  /**
   * 生日
   */
  teacher_date_of_birth?: string;
  /**
   * 教职工联系电话
   */
  teacher_mobile?: string;
  /**
   * 教职工名称
   */
  teacher_name?: string;
  /**
   * 教职工号
   */
  teacher_number?: string;
}
export const searchMembers = (params: SearchMembersParams & PageParams): Result<PageResult<Org>> =>
  HttpSrv().get('/school/v1/organization/members/page', {
    params: { school_id: Utils.getProps('schoolInfo')?.school_id, ...params },
  });
